﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LabTurtorial
{
    public partial class Lab03 : Form
    {
        public Lab03()
        {
            InitializeComponent();
            lvBalance.Columns.Add("Years");
            lvBalance.Columns.Add("Amount");
            lvBalance.View = View.Details;

        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            string principal = txtPrincipal.Text;
            float pm = Convert.ToInt64(principal);
            float incre = Convert.ToInt64(txtInterestRate.Text);
            int count = (int)nmYears.Value;
            List<Money> list = GetMoneyIncre(pm, count, incre);
            fillListView(list);

        }
        private void fillListView(List<Money> list)
        {
            lvBalance.Items.Clear();
            foreach (Money money in list)
            {
                string y = money.Year.ToString();
                string m = money.M.ToString();
                String[] str = new String[] { y, m };
                var item = new ListViewItem(str);
                lvBalance.Items.Add(item);
            }

        }
        private List<Money> GetMoneyIncre(float money, int years, float incre)
        {
            List<Money> list = new List<Money>();
            float m = money;
            for (int i = 1; i <= years; i++)
            {
                int y = i;
                m = m + m * incre / 100;
                Money mon = new Money(y, m);
                list.Add(mon);
            }
            return list;
        }
    }
    class Money
    {
        private float m;

        public float M
        {
            get { return m; }
            set { m = value; }
        }
        private int year;

        public int Year
        {
            get { return year; }
            set { year = value; }
        }
        public Money(int y, float m)
        {
            this.year = y;
            this.m = m;
        }
    }
}
